package org.boge.sharpdoc.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.boge.sharpdoc.dao.DownloadHistoryDao;
import org.boge.sharpdoc.bean.DownloadHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DownloadHistoryService {
    @Autowired
    private DownloadHistoryDao downloadHistoryDao;

    public List<DownloadHistory> findByUidAndDocid(Long phone, Integer docid) {
        return downloadHistoryDao.findByUidAndDocid(phone, docid);
    }

    public Integer addItem(Long phone, Integer docid) {
        return downloadHistoryDao.addItem(phone, docid);
    }

    public PageInfo<DownloadHistory> getAllWithPage(Integer index, Integer pageSize) {
        return PageHelper.startPage(index, pageSize, "dltime desc").doSelectPageInfo(() -> downloadHistoryDao.findAll());
    }
}